home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-17 | 28.9 KB | 1,319 lines | [TEXT/ALFA] |
- #================================================================================
- # Copyright 1994 by Scott W. Brim. You may use this software freely, and
- # distribute it freely as long as the receiver is not obligated in any
- # way by receiving it. If you want to distribute it in any other way, contact
- # me at swb1@cornell.edu and we'll see if we can work something out. Special
- # allowances are not unusual.
- #================================================================================
- #================================================================================
- #
- # html.tcl: macros and bindings for HTML documents
- #
- # Version 0.15
- #
- # You must have Alpha 5.85 or better to use this distribution, and Alpha
- # 5.92 or better to use its advanced features. If you don't, get the
- # most recent version from cs.rice.edu under public/Alpha. For
- # information on installation and customization see HTML Help. Ideas
- # were originally taken from Marc Andreesen's html.el and Tom Scavo's
- # latex.tcl
- #
- # If you make improvements to this environment, please share them!
- #
- # Scott Brim <swb1@cornell.edu>
- #
- #================================================================================
- #
- # Change Log:
- #
- # Version 0.15, 17 August 1994
- #
- # HTML mode is now integrated into the main Alpha distribution.
- # Better documentation all around.
- # Use newModeVar and shadowing; remove requirement that certain flags
- # be set before or after html.tcl is loaded.
- #
- # Previous change history available if you're really interested.
- #
- #================================================================================
- #
- # To Be Done:
- # Fuller HTML 2.0 implementation. When it's complete we'll have V1.0.
- # Add better color support with wordBreak and wordBreakPreface?
- # An option, htmlCompactPreferred, for people who prefer compact discursive
- # lists.
- # Optionally close P, LI, DD, DL. Put this under the control of an
- # option htmlPreferFull, which will include htmlUseHeadAndBody too.
- # Do something about indentation when filling?
- # Better searching for headers for HTMLMarkFile, e.g. to find headers even
- # when there are IMGs embedded in them.
- # Optional: various length dashes (with Apple-like keybindings);
- # "id" (not name) in all tags, generated automatically; doctype;
- # strikethrough style, and so on.
- # HTML's menu will have an "HTML 3" in it, which will totally switch the
- # menu. In the HTML 3 menu the same position will revert back.
- # Whether to come up in HTML 2 or HTML 3 mode will depend on a
- # user-settable variable.
- # When adding title, if one already exists, replace it.
- # A proc to leap from anchor to href and vice versa across multiple
- # documents.
- # htmlFillParagraph
- # For new disc entries: want compact vs. ordinary (check context)
- # "Balance"-type cmd on cmd-B, to mark text between matching tags.
- # Proc in menu to take selected text & convert chars to char entities as
- # needed.
- # Maybe a submenu under HREF with common URL templates?
- # Proc to force quotation marks in all hrefs.
- # Insert template text in one lump, so that one Undo removes whole thing.
- # Proc for automatic generation of table of contents?
- # Anything marked with "xxx"
- #
- #================================================================================
-
- proc loadHTML {} {
- global HOME modes
- addUserLine "\r\# The following lines install the HyperText Markup Language Mode"
- addUserLine "source \"$HOME:Tcl:UserCode:html.tcl\""
- addUserLine "catch {htmlDummy}"
- addUserLine "enableMenuItem -m install HTML 0\r"
-
- enableMenuItem -m install HTML 0
- set modes [lsort $modes]
- }
-
- #This icon is present in Alpha 5.86 and beyond. Check version.
- proc htmlAlphaVersion {} {
- regexp {[0-9.]+} [version] vers
- return $vers
- }
- if [expr [htmlAlphaVersion] < "5.86"] {
- set htmlMenu "Html"
- } else {
- set htmlMenu "•942"
- }
-
- set htmlCommentPreString "<!-- "
- set htmlCommentSufString " -->"
-
- #
- # Add mode to mode list. Requires 5.85 and after.
- #
- lappend modes HTML
- #addMenuItem -m $helpMenu "HTML Help"
- set modeMenus(HTML) htmlMenu
- lappend allModeMenus htmlMenu
- lappend modeSuffixes {*.html} { set winMode HTML }
- lappend modeSuffixes {*.HTML} { set winMode HTML }
- set dummyProc(HTML) htmlDummy
-
- newModeVar HTML wordBreakPreface {[^a-zA-Z0-9_/]} 0
- newModeVar HTML wordBreak {[a-zA-Z0-9_/]+} 0
- newModeVar HTML elecLBrace 0 1
- newModeVar HTML elecRBrace 0 1
- newModeVar HTML electricSemi 0 1
- newModeVar HTML wordWrap 1 1
- newModeVar HTML prefixString $htmlCommentPreString 0
- newModeVar HTML suffixString $htmlCommentSufString 0
- newModeVar HTML optionIsMeta 1 1
- # Should tags be lower case?
- newModeVar HTML htmlUseLowerCase 0 1
- # Default number of discursive list entries
- newModeVar HTML htmlDLEntries 3 0
- # Should TITLE generate HEAD and BODY?
- newModeVar HTML htmlUseHeadAndBody 0 1
- # Should •'s be inserted?
- newModeVar HTML htmlUseTabMarks 1 1
- # Use opt-cmd or ctl-cmd? Hack for int'l users.
- newModeVar HTML htmlUseCtlCmd 0 1
- # Prefer compact or open discursive lists?
- newModeVar HTML htmlCompactDiscLists 0 1
-
- #
- # If user changes these, we need to rebind a lot of keys
- #
- trace vdelete htmlUseCtlCmd w htmlTraceUCC
- trace variable htmlUseCtlCmd w htmlTraceUCC
- proc htmlTraceUCC {nm1 nm2 op} {
- htmlBindKeys
- return $nm1
- }
-
- trace vdelete htmlCompactDiscLists w htmlTraceCDL
- trace variable htmlCompactDiscLists w htmlTraceCDL
- proc htmlTraceCDL {nm1 nm2 op} {
- htmlBindKeys
- return $nm1
- }
-
-
- #
- # color support
- #
- set HTMLKeyWords {}
- regModeKeywords -b $htmlCommentPreString $htmlCommentSufString -m {<} -c red -k blue HTML $HTMLKeyWords
- #unset HTMLKeyWords
-
- ######################################################################
- # Internal Globals
- ######################################################################
- set htmlLastLink ""
- set htmlCurSel ""
- set htmlIsSel 0
-
- proc HTMLMarkFile {} {
- set end [maxPos]
- set pos 0
- set l {}
- set exp {^(<[Aa][^>]*>)?<([Hh][1-6]>[^<]*)</[Hh][1-6]>}
-
- while {![catch {search -f 1 -r 1 -m 0 -i 0 $exp $pos} res]} {
- set start [lindex $res 0]
- set end [lindex $res 1]
- set text [lindex [split [getText $start $end] "<>"] 2]
- set indlevel [getText [expr $start + 2] [expr $start + 3]]
-
- if {$indlevel > 0 && $indlevel < 7} {
- set lab [string range " " 2 $indlevel]
- append lab $indlevel " " $text
- setNamedMark $lab $start $start $end
- }
-
- set pos $end
- }
- }
-
- # That's it for hooking into Alpha's mode mechanisms, the rest is just
- # straight html stuff.
-
- ######################################################################
- # General Support Routines
- ######################################################################
-
- # Snatch the current selection into htmlCurSel, set flag whether there is one
- proc htmlGetSel {} {
- global htmlCurSel
- global htmlIsSel
- set htmlCurSel [getSelect]
- set htmlIsSel [string length $htmlCurSel]
- set htmlCurSel [string trim $htmlCurSel]
- }
-
- # xxx - not done yet
- # This thing is supposed to look where the cursor is and remove the
- # outermost tag marks, so automatically converted stuff can be
- # beautified more easily. I'm not sure how it should behave. I'm not
- # sure what to do if the selection spans a tag delimiter, for example.
- proc htmlUnTag {} {
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- createTmark htmlUnTagMark [getPos]
- search -f 0 -r 1 "<\[\^<>\]\*</\.\*>"
- }
-
- ######################################################################
- # Tags
- ######################################################################
-
- # Build a tag boundary. Decide if upper or lower case.
- proc htmlDoTag {text} {
- global htmlUseLowerCase
- insertText "<"
- insertText [expr {${htmlUseLowerCase}?[string tolower $text]:[string toupper $text]}]
- insertText ">"
- }
-
- # This is used for all simple tags
- proc htmlBuildTag {ftype} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlDoTag $ftype
- insertText $htmlCurSel
- set currpos [getPos]
- htmlDoTag /$ftype
- # set c [lookAt [getPos]]
- # if {$c != "\ "} {insertText " "} else {forwardChar}
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- }
-
- # This is used for tags that should be on their own lines
- proc htmlBuildCRTag {ftype} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- htmlDoTag $ftype
- insertText $htmlCurSel
- set currpos [getPos]
- htmlDoTag /$ftype
- set start [getPos]
- set end [nextLineStart $start]
- set text [getText $start $end]
- carriageReturn
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- }
-
- # This is used for tags that should be surrounded by empty lines
- proc htmlBuildCR2Tag {ftype} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- # note the tags are placed at the left margin, ignoring current indent
- htmlOpenCR ; insertText "\n"
- htmlDoTag $ftype
- carriageReturn
- insertText $htmlCurSel
- set currpos [getPos]
- insertText "\n"
- htmlDoTag /$ftype
- htmlCloseCR ; carriageReturn
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- }
-
- #
- # Here are all the things that use them
- #
-
- proc htmlTagAddress {} {
- htmlBuildCRTag "ADDRESS"
- message "Address"
- }
- proc htmlTagBlockquote {} {
- htmlBuildCR2Tag "BLOCKQUOTE"
- message "Blockquote"
- }
- proc htmlTagBold {} {
- htmlBuildTag "B"
- message "Bold"
- }
- proc htmlTagCite {} {
- htmlBuildTag "CITE"
- message "Cite"
- }
- proc htmlTagCode {} {
- htmlBuildTag "CODE"
- message "Code"
- }
- proc htmlTagDfn {} {
- htmlBuildTag "DFN"
- message "Definition"
- }
- proc htmlTagEmphasized {} {
- htmlBuildTag "EM"
- message "Emphasized"
- }
- proc htmlTagFixed {} {
- htmlBuildTag "TT"
- message "Fixed Width"
- }
- proc htmlTagForm {} {
- htmlBuildCR2Tag "FORM"
- message "Form"
- }
- proc htmlTagHR {} {
- htmlDoTag "HR"
- message "Horizontal Rule"
- }
- proc htmlTagItalic {} {
- htmlBuildTag "I"
- message "Italic"
- }
- proc htmlTagKeyboard {} {
- htmlBuildTag "KBD"
- message "Keyboard"
- }
- proc htmlTagUnderline {} {
- htmlBuildTag "U"
- message "Underline"
- }
- proc htmlTagSample {} {
- htmlBuildCRTag "SAMP"
- message "Sample"
- }
- proc htmlTagStrong {} {
- htmlBuildTag "STRONG"
- message "Strong emphasis"
- }
- proc htmlTagVarname {} {
- htmlBuildTag "VAR"
- message "Variable name"
- }
- proc htmlTagPreformatted {} {
- htmlBuildCR2Tag "PRE"
- message "Pre-formatted"
- }
- proc htmlTagListing {} {
- htmlBuildCR2Tag "LISTING"
- beep
- message "Use 'Preformatted' instead"
- }
- proc htmlTagXMP {} {
- htmlBuildCR2Tag "XMP"
- beep
- message "Use 'Preformatted' instead"
- }
-
- proc htmlTagTitle {} {
- global htmlUseTabMarks
- global htmlUseHeadAndBody
- global htmlCurSel
- global htmlIsSel
- if {$htmlUseHeadAndBody} {
- htmlGetSel
- set htmlTTIsSel $htmlIsSel
- if {$htmlTTIsSel} {
- set htmlTTCurSel $htmlCurSel
- deleteSelection
- }
- htmlDoTag "HTML"
- htmlBuildCRTag "HEAD"
- htmlBuildCRTag "TITLE"
- if {$htmlTTIsSel} {
- insertText $htmlTTCurSel
- } else {
- createTMark htmlTTMark [getPos]
- }
- htmlTabNext; htmlTabNext
- htmlBuildCR2Tag "BODY"
- if {!$htmlTTIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- } else {
- createTMark htmlTTMark [getPos]
- }
- htmlTabNext
- htmlDoTag "/HTML"
- gotoTMark htmlTTMark
- removeTMark htmlTTMark
- } else {
- htmlBuildCRTag "TITLE"
- }
- message "Document title"
- }
-
- proc htmlTagHeader1 {} {
- htmlBuildCRTag "H1"
- }
- proc htmlTagHeader2 {} {
- htmlBuildCRTag "H2"
- }
- proc htmlTagHeader3 {} {
- htmlBuildCRTag "H3"
- }
- proc htmlTagHeader4 {} {
- htmlBuildCRTag "H4"
- }
- proc htmlTagHeader5 {} {
- htmlBuildCRTag "H5"
- }
- proc htmlTagHeader6 {} {
- htmlBuildCRTag "H6"
- }
-
-
- #
- # Lists: Puts <cr>s before and after a list, inserts <li>, leaves the
- # insertion point there. If anything is selected, makes it the first item.
- #
- proc htmlBuildList {ltype} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- htmlDoTag $ltype
- carriageReturn
- htmlDoTag "LI"
- insertText " "
- if {$htmlIsSel} { # bullet 1 already full
- insertText $htmlCurSel
- carriageReturn
- htmlDoTag "LI"
- insertText " "
- }
- set currpos [getPos]
- carriageReturn
- htmlDoTag /$ltype
- carriageReturn
- if {!$htmlIsSel && $htmlUseTabMarks} {insertText "•"}
- htmlCloseCR
- if {!$htmlIsSel} {goto $currpos}
-
- }
-
- # Add list entry. If there is a selection, make it the entry.
- proc htmlTagListEntry {} {
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- htmlOpenCR
- htmlDoTag "LI"
- insertText " " $htmlCurSel
- message "New entry"
- }
-
- #
- # Here are all the things that use buildList:
- #
-
- proc htmlTagBulleted {} {
- htmlBuildList "UL"
- message "Bulleted list"
- }
- proc htmlTagNumbered {} {
- htmlBuildList "OL"
- message "Numbered list"
- }
- proc htmlTagMenu {} {
- htmlBuildList "MENU"
- message "Menu"
- }
- proc htmlTagDirectory {} {
- htmlBuildList "DIR"
- message "Directory"
- }
-
-
- #
- # Discursive Lists (terms and description tags)
- #
- # The selection becomes the *description* (*not* the term)
- #
-
- # Build a "compact" glossary
- proc htmlDiscCompact {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- global htmlDLEntries
- if {![catch {prompt "Compact Discursive List: how many entries?" $htmlDLEntries} \
- numberEntries] && $numberEntries > 0} {
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- htmlDoTag "DL COMPACT"
- carriageReturn
- htmlDoTag "DT"
- insertText " "
- set currpos [getPos]
- insertText "\t"
- htmlDoTag "DD"
- insertText " "
- if {$htmlIsSel} {
- insertText $htmlCurSel
- } else {
- if {$htmlUseTabMarks} {insertText " •"}
- }
- for {set i 1} {$i < $numberEntries} {incr i} {
- carriageReturn
- htmlDoTag "DT"
- if {$htmlUseTabMarks} {insertText " •"}
- insertText "\t"
- htmlDoTag "DD"
- if {$htmlUseTabMarks} {insertText " •"}
- }
- carriageReturn
- htmlDoTag "/DL"
- carriageReturn
- if {$htmlUseTabMarks} {insertText "•"}
- htmlCloseCR
- goto $currpos
- }
- }
-
- # Build a discursive list with more space
- proc htmlDiscLong {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- global htmlDLEntries
- if {![catch {prompt "Discursive List: how many entries?" $htmlDLEntries} \
- numberEntries] && $numberEntries > 0} {
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- htmlDoTag "DL"
- carriageReturn
- htmlDoTag "DT"
- insertText " "
- set currpos [getPos]
- carriageReturn
- insertText "\t"
- htmlDoTag "DD"
- insertText " "
- if {$htmlIsSel} {
- insertText $htmlCurSel
- } else {
- if {$htmlUseTabMarks} {insertText " •"}
- }
- for {set i 1} {$i < $numberEntries} {incr i} {
- carriageReturn ; carriageReturn
- backwardChar
- deleteChar
- htmlDoTag "DT"
- if {$htmlUseTabMarks} {insertText " •"}
- carriageReturn
- insertText "\t"
- htmlDoTag "DD"
- if {$htmlUseTabMarks} {insertText " •"}
- }
- carriageReturn
- backwardChar
- deleteChar
- htmlDoTag "/DL"
- carriageReturn
- if {$htmlUseTabMarks} {insertText "•"}
- htmlCloseCR
- goto $currpos
- }
- }
-
- # Add an individual entry to a discursive list
- proc htmlTagDiscEntry {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- htmlDoTag "DT"
- insertText " "
- set currpos [getPos]
- insertText "\t"
- htmlDoTag "DD"
- insertText " "
- if {$htmlIsSel} {
- insertText $htmlCurSel
- } else {
- if {$htmlUseTabMarks} {insertText "•"}
- }
- htmlCloseCR
- goto $currpos
- }
-
-
- #
- # hrefs
- #
-
- # An href points to an anchor
- # If text is selected it is made clickable.
- proc htmlTagHref {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- global htmlLastLink
- global htmlUseLowerCase
- htmlGetSel
-
- set defref $htmlLastLink
- if {![catch {prompt "HREF to?" $defref} defref]} {
- if {$htmlIsSel} deleteSelection
- if {$htmlUseLowerCase} {
- insertText "<a href=\""
- } else {
- insertText "<A HREF=\""
- }
- insertText $defref "\">" $htmlCurSel
- set currpos [getPos]
- htmlDoTag "/A"
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- set htmlLastLink $defref
- }
- }
-
- # An anchor is something which is pointed to by an href.
- # If text is selected it is the object of the href.
- proc htmlTagAnchor {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- global htmlLastLink
- global htmlUseLowerCase
- htmlGetSel
- if {![catch {prompt "Anchor name?" $htmlLastLink} defref]} {
- if {$htmlIsSel} deleteSelection
- if {$htmlUseLowerCase} {
- insertText "<a name=\""
- } else {
- insertText "<A NAME=\""
- }
- insertText $defref "\">" $htmlCurSel
- set currpos [getPos]
- htmlDoTag "/A"
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- set htmlLastLink $defref
- }
- }
-
- # Inline image href
- # If text is selected it is made clickable.
- proc htmlTagImg {} {
- global HOME
- global htmlCurSel
- global htmlIsSel
- global htmlUseLowerCase
- htmlGetSel
- if {$htmlIsSel} {
- set defref $htmlCurSel
- } else {
- set defref ""
- }
- if {![catch {prompt "Image URL?" $defref} defref]} {
- if {$htmlIsSel} deleteSelection
- htmlOpenCR
- if {$htmlUseLowerCase} {
- insertText "<a img src=\""
- } else {
- insertText "<IMG SRC=\""
- }
- insertText $defref "\">"
- htmlCloseCR
- message "Inline image"
- }
- }
-
-
- ######################################################################
-
-
- #
- # The following are straight from latex.tcl (thanks!)
- #
-
- # A boolean function which takes any string and tests to see if
- # that string contains all whitespace characters. Carriage returns
- # are considered whitespace, as are spaces and tabs.
- proc htmlIsWhite {anyString} {
- set len [string length $anyString]
- for {set i 0} {$i < $len} {incr i} {
- set c [string index $anyString $i]
- if {($c != "\ ") && ($c != "\t") && ($c != "\r")} then {return 0}
- }
- return 1
- }
-
- # Insert a carriage return at the insertion point if any
- # character preceding the insertion point (on the same line)
- # is a non-whitespace character.
- proc htmlOpenCR {} {
- set end [getPos]
- set start [lineStart $end]
- set text [getText $start $end]
- if {![htmlIsWhite $text]} carriageReturn
- }
-
- # Insert a carriage return at the insertion point if any
- # character following the insertion point (on the same line)
- # is a non-whitespace character.
- proc htmlCloseCR {} {
- set start [getPos]
- set end [nextLineStart $start]
- set text [getText $start $end]
- if {![htmlIsWhite $text]} carriageReturn
- }
-
- # Set up tab stop mechanism.
- proc htmlTabGoto {directionIndicator} {
- set searchResult [search -n -f $directionIndicator -m 0 -i 1 -r 0 {•} [getPos]]
- if {[llength $searchResult] == 0} then {
- message "Tab stop not found"
- return 0
- } else {
- goto [lindex $searchResult 0]
- return 1
- }
- }
- proc htmlTabNext {} {
- if {[htmlTabGoto 1]} {deleteChar}
- }
- proc htmlTabPrev {} {
- if {[htmlTabGoto 0]} {deleteChar}
- }
-
- proc htmlTabDeleteAll {} {
- createTMark htmlDelTabMark [getPos]
- goto 0
- set searchpos 0
- while {1} {
- if {$searchpos == [maxPos]} break
- set searchResult [search -f 1 -r 0 -m 0 -n {•} $searchpos]
- if {[llength $searchResult] == 0} break
- deleteText [lindex $searchResult 0] [lindex $searchResult 1]
- set searchpos [getPos]
- }
- message "Tab stops deleted"
- gotoTMark htmlDelTabMark
- removeTMark htmlDelTabMark
- }
-
- #########################
- #
- # Procs for HTML special characters
- #
- #########################
-
- # These three are bound to the single keys
- proc htmlLt {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText "<\;"
- }
- proc htmlGt {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText ">\;"
- }
- proc htmlAmp {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText "&\;"
- }
-
- # The next three allow you to input the real characters
- proc htmlLT {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText "<"
- }
- proc htmlGT {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText ">"
- }
- proc htmlAMP {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- insertText "&"
- }
-
-
-
- ########################################################################
- #
- # Menus
- #
- ########################################################################
- # Break
- proc htmlBreak {} {
- htmlDoTag "BR"
- carriageReturn
- }
-
- # CRs before <p>
- proc htmlParagraph {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- carriageReturn
- carriageReturn
- htmlDoTag "P"
- }
-
- # no CRs before <p>
- proc htmlParaMark {} {
- global htmlIsSel
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlDoTag "P"
- }
-
- proc htmlComment {} {
- global htmlUseTabMarks
- global htmlCurSel
- global htmlIsSel
- global htmlCommentPreString htmlCommentSufString
-
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- htmlOpenCR
- insertText $htmlCommentPreString $htmlCurSel
- set currpos [getPos]
- insertText $htmlCommentSufString
- htmlCloseCR
- if {!$htmlIsSel} {
- if {$htmlUseTabMarks} {insertText "•"}
- goto $currpos
- }
- }
-
- proc htmlMenuItem {menu item} {
- global htmlIsSel
-
- case $menu in {
- {"Html" •942} {
- case $item in {
- "newParagraph" {htmlParagraph}
- "paragraphMark" {htmlParaMark}
- "break" {htmlBreak}
- "comment" {htmlComment}
- "removeTabMarks" {htmlTabDeleteAll}
- }
- }
- "Headers" {
- case $item in {
- "header1" {htmlTagHeader1}
- "header2" {htmlTagHeader2}
- "header3" {htmlTagHeader3}
- "header4" {htmlTagHeader4}
- "header5" {htmlTagHeader5}
- "header6" {htmlTagHeader6}
- }
- }
- "Styles" {
- case $item in {
- "emphasis" {htmlTagEmphasized}
- "strong" {htmlTagStrong}
- "bold" {htmlTagBold}
- "italic" {htmlTagItalic}
- "fixedWidth" {htmlTagFixed}
- "keyboard" {htmlTagKeyboard}
- "underline" {htmlTagUnderline}
- }
- }
- "Lists" {
- case $item in {
- "addEntry" {htmlTagListEntry}
- "bulleted" {htmlTagBulleted}
- "numbered" {htmlTagNumbered}
- "menu" {htmlTagMenu}
- "directory" {htmlTagDirectory}
- }
- }
- {"Other Tags" "otherTags"} {
- case $item in {
- "preformatted" {htmlTagPreformatted}
- "title" {htmlTagTitle}
- "address" {htmlTagAddress}
- "blockquote" {htmlTagBlockquote}
- "cite" {htmlTagCite}
- "code" {htmlTagCode}
- "definition" {htmlTagDfn}
- "form" {htmlTagForm}
- "horizRule" {htmlTagHR}
- "listing" {htmlTagListing}
- "sample" {htmlTagSample}
- "variable" {htmlTagVarname}
- "xMP" {htmlTagXMP}
- }
- }
- {"discursiveLists" "Discursive Lists"} {
- case $item in {
- "addEntry" {htmlTagDiscEntry}
- "compactList" {htmlDiscCompact}
- "moreSpace" {htmlDiscLong}
- }
- }
- "Hyperlinks" {
- case $item in {
- "addHref" {htmlTagHref}
- "addAnchor" {htmlTagAnchor}
- "addIMG" {htmlTagImg}
- }
- }
- # Characters: only work by putting a leading space on menu items
- "Characters" {
- case $item in {
- "lessthan" {htmlLt}
- "greaterthan" {htmlGt}
- "ampersand" {htmlAmp}
- default {
- htmlGetSel
- if {$htmlIsSel} { deleteSelection }
- set item [string trim $item]
- insertText &${item}\;
- }
- }
- }
- }
-
- }
-
- menu -n $htmlMenu -p htmlMenuItem {
-
- "spellcheckWindow"
- "(-"
- "newParagraph"
- "paragraphMark"
- "break"
- "comment"
- "removeTabMarks"
- "(-"
-
- {menu -n Headers -p htmlMenuItem {
- "header1"
- "header2"
- "header3"
- "header4"
- "header5"
- "header6"
- }}
-
- {menu -n Styles -p htmlMenuItem {
- "emphasis"
- "strong"
- "bold"
- "italic"
- "fixedWidth"
- "Keyboard"
- "Underline"
- }}
-
- {menu -n "Lists" -p htmlMenuItem {
- "addEntry"
- "(-"
- "bulleted"
- "numbered"
- "menu"
- "directory"
- }}
-
- {menu -n "Discursive Lists" -p htmlMenuItem {
- "Add Entry"
- "(-"
- "compactList"
- "moreSpace"
- }}
-
- {menu -n "Other Tags" -p htmlMenuItem {
- "preformatted"
- "title"
- "address"
- "blockquote"
- "cite"
- "code"
- "definition"
- "form"
- "horizRule"
- "listing"
- "sample"
- "variable"
- "xMP"
- }}
-
- {menu -n Hyperlinks -p htmlMenuItem {
- "addHref"
- "addAnchor"
- "addIMG"
- }}
-
- "(-"
-
- {menu -n Characters -p htmlMenuItem {
- "lessthan"
- "greaterthan"
- "ampersand"
- "(-"
- " Aacute"
- " Acirc"
- " Acircumflex"
- " Adieresis"
- " AE"
- " AElig"
- " Agrave"
- " Aring"
- " Atilde"
- " Auml"
- " Ccedil"
- " Ccedilla"
- " Delta"
- " Eacute"
- " Ecirc"
- " Ecircumflex"
- " Edieresis"
- " Egrave"
- " Eth"
- " Euml"
- " Iacute"
- " Icirc"
- " Icircumflex"
- " Idieresis"
- " Igrave"
- " Iuml"
- " Ntilde"
- " OE"
- " Oacute"
- " Ocirc"
- " Ocircumflex"
- " Odieresis"
- " Ograve"
- " Omega"
- " Oslash"
- " Otilde"
- " Ouml"
- " Pi"
- " Sigma"
- " Thorn"
- " Uacute"
- " Ucirc"
- " Ucircumflex"
- " Udieresis"
- " Ugrave"
- " Uuml"
- " Yacute"
- " Ydieresis"
- " Ygrave"
- " aacute"
- " acirc"
- " acircumflex"
- " adieresis"
- " ae"
- " aelig"
- " agrave"
- " apple"
- " approxequal"
- " aring"
- " atilde"
- " auml"
- " breve"
- " bullet"
- " caron"
- " ccedil"
- " ccedilla"
- " cedilla"
- " cent"
- " circumflex"
- " copyright"
- " currency"
- " dagger"
- " daggerdbl"
- " degree"
- " dieresis"
- " divide"
- " dotaccent"
- " dotlessi"
- " eacute"
- " eacute"
- " ecirc"
- " ecircumflex"
- " edieresis"
- " egrave"
- " ellipsis"
- " emdash"
- " emsp"
- " endash"
- " ensp"
- " eth"
- " euml"
- " exclamdown"
- " fi"
- " fl"
- " florin"
- " fraction"
- " germandbls"
- " greaterequal"
- " guillemotleft"
- " guillemotright"
- " guilsinglleft"
- " guilsinglright"
- " hellip"
- " hungarumlaut"
- " iacute"
- " icirc"
- " icircumflex"
- " idieresis"
- " igrave"
- " infinity"
- " integral"
- " iuml"
- " lessequal"
- " logicalnot"
- " lozenge"
- " macron"
- " mdash"
- " mu"
- " nbsp"
- " ndash"
- " nobrkspace"
- " notequal"
- " ntilde"
- " oacute"
- " ocirc"
- " ocircumflex"
- " odieresis"
- " oe"
- " ogonek"
- " ograve"
- " ordfeminine"
- " ordmasculine"
- " oslash"
- " otilde"
- " ouml"
- " paragraph"
- " partialdiff"
- " periodcentered"
- " perthousand"
- " pi"
- " plusminus"
- " questiondown"
- " quot"
- " quotedblbase"
- " quotedblleft"
- " quotedblright"
- " quoteleft"
- " quoteright"
- " quotesinglbase"
- " radical"
- " registered"
- " ring"
- " section"
- " shy"
- " sterling"
- " szlig"
- " thorn"
- " tilde"
- " trademark"
- " uacute"
- " ucirc"
- " ucircumflex"
- " udieresis"
- " ugrave"
- " uuml"
- " vellip"
- " yacute"
- " ydieresis"
- " yen"
- " yuml"
- }}
-
- }
-
- #############################################################################
- #
- # Key Bindings.
- #
- # abbreviations: <o> = option, <z> = control, <s> = shift, <c> = command
- #
- #############################################################################
-
- proc htmlBindKeys {} {
- global htmlCompactDiscLists htmlUseCtlCmd
-
- # this is in 5.92 and beyond.
- catch {deleteModeBindings "HTML"}
-
- if (![info exists htmlCompactDiscLists]) {
- set htmlCompactDiscLists 0
- }
- if (![info exists htmlUseCtlCmd]) {
- set htmlUseCtlCmd 0
- }
-
- if ($htmlCompactDiscLists) {
- set htmlDLPref htmlDiscCompact
- set htmlDLAlt htmlDiscLong
- } else {
- set htmlDLPref htmlDiscLong
- set htmlDLAlt htmlDiscCompact
- }
- if ($htmlUseCtlCmd) {set htmlBStr "zc"} else {set htmlBStr "oc"}
- if ($htmlUseCtlCmd) {set htmlSBStr "szc"} else {set htmlSBStr "soc"}
-
- bind 0x30 htmlTabNext "HTML"
- bind 0x30 <s> htmlTabPrev "HTML"
-
- # enter & opt-cmd-enter for new-paragraph
- bind Enter htmlParagraph "HTML"
- bind Enter <$htmlBStr> htmlParaMark "HTML"
- # (for powerbook 100) xxx - this feels dangerous
- bind 0x34 htmlParagraph "HTML"
- bind 0x34 <$htmlBStr> htmlParaMark "HTML"
- # for those with awkward Enter keys
- bind 'm' <z> htmlParagraph "HTML"
-
- # Comment on semicolon
- bind 0x29 <$htmlBStr> htmlComment "HTML"
-
- bind '0' <$htmlBStr> htmlTagTitle "HTML"
- bind '1' <$htmlBStr> htmlTagHeader1 "HTML"
- bind '1' <$htmlSBStr> htmlBreak "HTML"
- bind '2' <$htmlBStr> htmlTagHeader2 "HTML"
- bind '3' <$htmlBStr> htmlTagHeader3 "HTML"
- bind '4' <$htmlBStr> htmlTagHeader4 "HTML"
- bind '5' <$htmlBStr> htmlTagHeader5 "HTML"
- bind '6' <$htmlBStr> htmlTagHeader6 "HTML"
-
- bind 'e' <$htmlBStr> htmlTagEmphasized "HTML"
- bind 's' <$htmlBStr> htmlTagStrong "HTML"
- bind 'b' <$htmlBStr> htmlTagBold "HTML"
- bind 'i' <$htmlBStr> htmlTagItalic "HTML"
- bind 'f' <$htmlBStr> htmlTagFixed "HTML"
- bind 'k' <$htmlBStr> htmlTagKeyboard "HTML"
-
- bind 'n' <$htmlBStr> htmlTagListEntry "HTML"
- bind 'u' <$htmlBStr> htmlTagBulleted "HTML"
- bind 'o' <$htmlBStr> htmlTagNumbered "HTML"
- bind 'm' <$htmlBStr> htmlTagMenu "HTML"
- bind 'd' <$htmlBStr> htmlTagDirectory "HTML"
-
- bind 'p' <$htmlBStr> htmlTagPreformatted "HTML"
- bind 't' <$htmlBStr> htmlTagTitle "HTML"
- bind 'c' <$htmlBStr> htmlTagCode "HTML"
- bind 'c' <$htmlSBStr> htmlTagCite "HTML"
- bind 'q' <$htmlBStr> htmlTagBlockquote "HTML"
- bind 's' <$htmlSBStr> htmlTagSample "HTML"
- bind 'a' <$htmlBStr> htmlTagAddress "HTML"
- bind 'v' <$htmlBStr> htmlTagVarname "HTML"
- bind 'l' <$htmlBStr> htmlTagListing "HTML"
- bind 'x' <$htmlBStr> htmlTagXMP "HTML"
-
- # Discursive List stuff
- bind 'n' <$htmlSBStr> htmlTagDiscEntry "HTML"
- bind 'g' <$htmlBStr> $htmlDLPref "HTML"
- bind 'g' <$htmlSBStr> $htmlDLAlt "HTML"
-
- # A "<" is something pointed at. ">" points to it.
- bind '.' <$htmlBStr> htmlTagHref "HTML"
- bind ',' <$htmlBStr> htmlTagAnchor "HTML"
-
- # An image, right near the usual href
- bind '/' <$htmlBStr> htmlTagImg "HTML"
-
- # "<", ">" and "&" insert their "&" versions. Shift inserts character.
- bind ',' <s> htmlLt "HTML"
- bind ',' <$htmlSBStr> htmlLT "HTML"
- bind '.' <s> htmlGt "HTML"
- bind '.' <$htmlSBStr> htmlGT "HTML"
- bind '7' <s> htmlAmp "HTML"
- bind '7' <$htmlSBStr> htmlAMP "HTML"
-
- # ISO character entities ...
- # I can't put all of them on bindings, and different users want
- # different ones. So skip it.
-
- }
-
- # bind the keys based on defaults. Shadowing will rebind later in
- # userStartup.tcl.
- htmlBindKeys
-
- proc htmlDummy {} {}
-